/**
* 即开即得
* 双色球自选
* curl http://localhost:8080
* curl --data "users=yi,er" http://localhost:8080/import
* curl http://localhost:8080/lucky
 */
package main

import (
	"fmt"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/mvc"

	"math/rand"
	"time"
)

type lotteryController struct {
	Ctx iris.Context
}

func newApp() *iris.Application {
	app := iris.New()
	mvc.New(app.Party("/")).Handle(&lotteryController{})
	return app
}

func main() {
	app := newApp()

	err := app.Run(iris.Addr(":8080"))
	if err != nil {
		fmt.Println("出错")
	}
}

// 即开即得型 http://localhost:8080/
func (c *lotteryController) Get() string {
	var prize string

	seed := time.Now().UnixNano()
	code := rand.New(rand.NewSource(seed)).Intn(10)

	switch {
	case code == 1:
		prize = "一等奖"
	case code >= 2 && code < 3:
		prize = "二等奖"
	case code >= 4 && code <= 6:
		prize = "三等奖"
	default:
		return fmt.Sprintf("code=%d<br>"+"没中奖", code)
	}
	return fmt.Sprintf("code=%d<br>"+"恭喜你获得：%s", code, prize)
}

// 双色球自选型 http://localhost:8080/prize
func (c *lotteryController) GetPrize() string {
	seed := time.Now().UnixNano()
	r := rand.New(rand.NewSource(seed))
	var prize [7]int
	//6个红色球 1-33
	for i := 0; i < 6; i++ {
		prize[i] = r.Intn(33) + 1
	}
	//蓝色球 1-16
	prize[6] = r.Intn(16) + 1

	return fmt.Sprintf("今日开奖号码是： %v", prize)
}
